<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>基础的get请求</h1>
    <form id="form" action="" method="">
        <input id="ipt" type="text">
        <button id="btn">输入学生id 查询他的详细信息</button>
    </form>
    <script>
        let btn = document.querySelector('#btn')
        let ipt = document.querySelector('#ipt')
        let form = document.querySelector('#form')
        form.onsubmit = function () {
                let userid = ipt.value
                let xhr = new XMLHttpRequest()
                xhr.open('get', `userinfo/${userid}?_=${Date.now()}`)
                xhr.send()
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status <= 299)) {

                        // console.log(xhr.responseText);
                        const data = JSON.parse(xhr.responseText)
                        console.log(data);
                    }
                }
                return false
            }
    </script>
</body>

</html>